package com.ilop.sthome.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.siterwell.familywellplus.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author skygge
 * @date 2020-03-21.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：选择头像方式
 */
public class ChooseImageDialog extends Dialog {

    @BindView(R.id.tv_select_album)
    TextView tvSelectAlbum;
    @BindView(R.id.tv_photograph)
    TextView tvPhotograph;
    @BindView(R.id.tv_photo_cancel)
    TextView tvPhotoCancel;

    private onChooseCallBack chooseCallBack;

    public ChooseImageDialog(Context context, onChooseCallBack callBack) {
        super(context, R.style.window_background2);
        this.chooseCallBack = callBack;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_choose_image);
        setCanceledOnTouchOutside(false);
        ButterKnife.bind(this);

        Window window = getWindow();
        assert window != null;
        WindowManager.LayoutParams params = window.getAttributes();
        //dialog显示位置，不设置默认居中
        window.setGravity(Gravity.BOTTOM);
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(params);

        tvPhotoCancel.setOnClickListener(view -> dismiss());

        tvSelectAlbum.setOnClickListener(view -> {
            chooseCallBack.startGallery();
            dismiss();
        });

        tvPhotograph.setOnClickListener(view -> {
            chooseCallBack.startCamera();
            dismiss();
        });
    }

    public interface onChooseCallBack{

        void startGallery();//启动图片选择

        void startCamera();//启动拍照
    }
}
